package com.yyds.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yyds.common.MyJSON;
import com.yyds.mapper.HospitalHospitalMapper;
import com.yyds.pojo.HospitalHospital;
import com.yyds.service.HospitalHospitalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@SuppressWarnings({"all"})
@Service("HospitalHospitalService")
public class HospitalHospitalServiceImpl implements HospitalHospitalService {

    @Autowired
    @Qualifier("hospitalHospitalMapper")
    private HospitalHospitalMapper hospitalHospitalMapper;

    @Override
    public MyJSON<HospitalHospital> queryHospitalHospitalService(Map<String, Object> params) {

        //mybatis分页 插件使用
        Integer page = Integer.parseInt(params.get("page") + "");
        Integer limit = Integer.parseInt(params.get("limit") + "");

        PageHelper.startPage(page,limit);
        List<HospitalHospital> hospitalList = hospitalHospitalMapper.queryHospitalHospitalMapper(params);
        //mybatis 的分页数据结构
        PageInfo<HospitalHospital> hospitalPageInfo = new PageInfo<>(hospitalList);

        MyJSON<HospitalHospital> hospitalMyJSON = new MyJSON<>();
        hospitalMyJSON.setCode(0);
        hospitalMyJSON.setMsg("分页列表数据");
        hospitalMyJSON.setCount(hospitalPageInfo.getTotal());
        hospitalMyJSON.setData(hospitalPageInfo.getList());

        return hospitalMyJSON;
    }

    @Override
    public Integer insertHospitalHospitalService(HospitalHospital hospital) {
        return hospitalHospitalMapper.insertHospitalHospitalMapper(hospital);
    }

    @Override
    public Integer deleteHospitalHospitalService(Integer hospital_id) {
        return hospitalHospitalMapper.deleteHospitalHospitalMapper(hospital_id);
    }

    @Override
    public Integer updateHospitalHospitalService(HospitalHospital newHospital) {
        return hospitalHospitalMapper.updateHospitalHospitalMapper(newHospital);
    }
}
